package com.mls.fivedistrict.server.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.mls.fivedistrict.common.PageFilter;
import com.mls.fivedistrict.dao.AdvertisingMapper;
import com.mls.fivedistrict.enums.TaskStatus;
import com.mls.fivedistrict.pojo.Advertising;
import com.mls.fivedistrict.server.AdvertisingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenxiuxiang on 2018/4/14.
 */
@Service
public class AdvertisingServiceImpl extends ServiceImpl<AdvertisingMapper, Advertising> implements AdvertisingService {
    @Autowired
    private AdvertisingMapper advertisingMapper;


//    @Autowired
//    AdvertisingMapper advertisingMapper;

//    @Override
//    public int addAdversing(Advertising advertising) {
//        return advertisingMapper.insertSelective(advertising);
//        int row = advertisingMapper.insert(advertising);
//        return row;
//    }

//    @Override
//    public int editAdversion(Advertising advertising) {
//        return advertisingMapper.updateByPrimaryKeySelective(advertising);
//        return advertisingMapper.updateById(advertising);
//    }

    @Override
    public List<Advertising> getAdversionList(PageFilter pageFilter) {
//        AdvertisingExample advertisingExample = new AdvertisingExample();
//        AdvertisingExample.Criteria criteria = advertisingExample.createCriteria();
//        criteria.andIsDeleteEqualTo(false);
//        criteria.andStatusEqualTo(TaskStatus.ENABLE.getValue());
//        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
//        List<Advertising> advertisings = advertisingMapper.selectByExample(advertisingExample);
//        return advertisings;
//        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
//        List<Advertising> advertisingList = advertisingMapper.selectList(pageFilter.getWrapper());
//        return advertisingList;
        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
        List<Advertising> advertisingList = advertisingMapper.selectList(Condition.create().eq("is_delete", false)//
                .eq("status", TaskStatus.ENABLE.getValue()));
        return advertisingList;
    }

//    @Override
//    public List<Advertising> getAdversionBackendList(PageFilter pageFilter) {
//        AdvertisingExample advertisingExample = new AdvertisingExample();
//        AdvertisingExample.Criteria criteria = advertisingExample.createCriteria();
//        criteria.andIsDeleteEqualTo(false);
//        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
//        List<Advertising> advertisings = advertisingMapper.selectByExample(advertisingExample);
//        return advertisings;
//        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
//        List<Advertising> advertisingList = advertisingMapper.selectList(pageFilter.getWrapper());
//        return advertisingList;
//    }

    @Override
    public List<Advertising> getAdversionListAndItem(PageFilter pageFilter) {
//        AdvertisingExample advertisingExample = new AdvertisingExample();
//        AdvertisingExample.Criteria criteria = advertisingExample.createCriteria();
//        criteria.andIsDeleteEqualTo(false);
//        advertisingExample.setOrderByClause("orders asc");
//        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
//        List<Advertising> advertisings = advertisingMapper.selectByExampleAndItem(advertisingExample);
//        return advertisings;
        PageHelper.startPage(pageFilter.getPageNum(), pageFilter.getPageSize());
        List<Advertising> advertisingList = advertisingMapper.selectListAndItem(pageFilter.getWrapper());
        return advertisingList;
    }


//    @Override
//    public Advertising getAdversing(Long id) {
//        Advertising advertising = advertisingMapper.selectByPrimaryKey(id);
//        return advertising;
//        return advertisingMapper.selectById(id);
//    }

    @Override
    public Advertising getAdversingAndItem(Long id) {
        Advertising advertising = advertisingMapper.selectByPrimaryKeyAndItem(id);
        return advertising;
    }
}
